import { Ast, Visitor } from "../ast";

export interface RedOpenContext {
    setting?: any;
    status?: `success` | 'fail' | 'opening' | 'wait';
    count?: number;
    close?: () => void;
    total?: number;
    hasWait?: boolean;
    open?: () => void;
    join?: () => void;
}
export abstract class RedOpenVisitor implements Visitor<RedOpenContext>{
    visitNode(node: Ast, ctx: RedOpenContext) {
        if (!node.visibleToUser) return;
        if (node.className) {
            const classNameSplit = node.className.split('.')
            const classNameEnd = classNameSplit.pop()
            const methodName = `visit${classNameEnd.charAt(0).toUpperCase() + classNameEnd.slice(1)}`
            if (this[methodName]) return this[methodName](node, ctx)
        }
        node.children.map(c => c.visit(this, ctx))
    }
    visitHorizontalScrollView(node: Ast, ctx: RedOpenContext) {
        if (node.id.endsWith(`tab_layout`)) {
            ctx.status = `fail`;
            return;
        }
        node.children.map(c => c.visit(this, ctx))
    }
}
